package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannerService;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(value = "频道管理",tags = "channel",description = "频道管理API")
@RestController
@RequestMapping("/api/v1/channel")
public class AdChannelController {
  
    @Autowired
    private AdChannerService adChannerService;

    @ApiOperation("频道分页列表查询")
    @PostMapping("/list")
    public ResponseResult findPage(@RequestBody ChannelDto channelDto){
        return adChannerService.findPage(channelDto);
    }


    @ApiOperation("频道列表新增")
    @PostMapping("/save")
    public ResponseResult add(@RequestBody AdChannel adChannel){
        return adChannerService.add(adChannel);
    }


    @ApiOperation("频道列表修改")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody AdChannel adChannel){
        return adChannerService.update(adChannel);
    }


    @ApiOperation("频道列表删除")
    @GetMapping("/del/{id}")
    public ResponseResult delete(@PathVariable("id")Integer id){
        return adChannerService.deleteById(id);
    }

    @GetMapping("/channels")
    public ResponseResult findAll() {
        List<AdChannel> list = adChannerService.list();
        return ResponseResult.okResult(list);
    }

}
